﻿using System;
using Autodesk.Revit.DB;
using RevitInteractiveUtility.ExternalEventManager;

namespace YJKAcquireDataComparison
{
	public class DelBoundaryRequest : IRequest
	{
		public int RequestId
		{
			get
			{
				return 2;
			}
		}

		public void DoRequest(object parameters = null)
		{
			DelBoundaryBean delBoundaryBean = null;
			if (parameters is DelBoundaryBean)
			{
				delBoundaryBean = (parameters as DelBoundaryBean);
			}
			this.DelBoundary(delBoundaryBean.UseForm);
		}

		private void DelBoundary(ReportDataListForm useForm)
		{
			Document useDoc = useForm.m_SrcDocM.UseDoc;
			Document useDoc2 = useForm.m_DesDocM.UseDoc;
			if (useDoc != null && useDoc2 != null)
			{
				Transaction transaction = new Transaction(useDoc, "Del SrcDocBoundary");
				transaction.Start();
				foreach (ReportData reportData in useForm.LstCheckReportData)
				{
					if (reportData.SrcObjectStructBase != null)
					{
						useDoc.Delete(reportData.SrcObjectStructBase.SrcLstBoundaryIDs);
					}
					if (reportData.DesObjectStructBase != null)
					{
						useDoc.Delete(reportData.DesObjectStructBase.SrcLstBoundaryIDs);
					}
				}
				transaction.Commit();
				Transaction transaction2 = new Transaction(useDoc2, "Del SrcDocBoundary");
				transaction2.Start();
				foreach (ReportData reportData2 in useForm.LstCheckReportData)
				{
					if (reportData2.SrcObjectStructBase != null)
					{
						useDoc2.Delete(reportData2.SrcObjectStructBase.DesLstBoundaryIDs);
					}
					if (reportData2.DesObjectStructBase != null)
					{
						useDoc2.Delete(reportData2.DesObjectStructBase.DesLstBoundaryIDs);
					}
				}
				transaction2.Commit();
			}
		}
	}
}
